/*************************************************************************
 * Name:
 * Email:
 *
 * Compilation:  javac Point.java
 * Execution:
 * Dependencies: StdDraw.java
 *
 * Description: An immutable data type for points in the plane.
 *
 *************************************************************************/

import java.util.Comparator;

public class Point implements Comparable<Point> {

	// compare points by slope
	public final Comparator<Point> SLOPE_ORDER = new Comparator<Point>() {

		@Override
		public int compare(Point o1, Point o2) {
			double slopeToO1 = slopeTo(o1);
			double slopeToO2 = slopeTo(o2);
			if (slopeToO1 > slopeToO2) {
				return 1;
			} else if (slopeToO1 < slopeToO2) {
				return -1;
			} else {
				return 0;
			}
		}
	};

	private final int x; // x coordinate
	private final int y; // y coordinate

	// create the point (x, y)
	public Point(int x, int y) {
		/* DO NOT MODIFY */
		this.x = x;
		this.y = y;
	}

	// plot this point to standard drawing
	public void draw() {
		/* DO NOT MODIFY */
		StdDraw.point(x, y);
	}

	// draw line between this point and that point to standard drawing
	public void drawTo(Point that) {
		/* DO NOT MODIFY */
		StdDraw.line(this.x, this.y, that.x, that.y);
	}

	// slope between this point and that point
	public double slopeTo(Point that) {
		if (that == null) {
			throw new NullPointerException();
		}
		
		if (x == that.x && y == that.y) {
			return Double.NEGATIVE_INFINITY;
		}
		
		double slope = (Integer.valueOf(that.y).doubleValue() - Integer
				.valueOf(y).doubleValue())
				/ (Integer.valueOf(that.x).doubleValue() - Integer.valueOf(x)
						.doubleValue());
		return slope;
	}

	// is this point lexicographically smaller than that one?
	// comparing y-coordinates and breaking ties by x-coordinates
	// Formally, the invoking point (x0, y0) is less than the argument point
	// (x1, y1) if and only if either y0 < y1 or if y0 = y1 and x0 < x1.
	public int compareTo(Point that) {
		if (y < that.y) {
			return -1;
		} else if (y == that.y && x < that.x) {
			return -1;
		} else if (y == that.y && x == that.x) {
			return 0;
		} else {
			return 1;
		}
	}

	// return string representation of this point
	public String toString() {
		/* DO NOT MODIFY */
		return "(" + x + ", " + y + ")";
	}

	// unit test
	public static void main(String[] args) {

	}
}